package com.wuyou.designPatterns.factory.abstractfactory;

import com.wuyou.designPatterns.factory.abstractfactory.factory.Factory;
import com.wuyou.designPatterns.factory.abstractfactory.factory.Link;
import com.wuyou.designPatterns.factory.abstractfactory.factory.Page;
import com.wuyou.designPatterns.factory.abstractfactory.factory.Tray;
import com.wuyou.designPatterns.factory.abstractfactory.listfactory.ListFactory;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

public class Main {


    public static void main(String[] args) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
//        Factory factory = Factory.getFactory(args[0]);
//        Link people = factory.createLink("人民日报", "http://www.people.com.cn");
//        Link gmw = factory.createLink("光明日报", "http://www.gmw.cn");
//
//        Link us_yahoo = factory.createLink("Yahoo!", "http://yahoo.com");
//        Link jp_yahoo = factory.createLink("Yahoo!Japan", "http://yahoo.co.jp");
//        Link excite = factory.createLink("Excite", "http://www.excite.com");
//        Link google = factory.createLink("Google", "http://www.google.com");
//
//        Tray traynews = factory.createTray("日报");
//        traynews.add(people);
//        traynews.add(gmw);
//
//        Tray trayyahoo = factory.createTray("Yahoo!");
//        trayyahoo.add(us_yahoo);
//        trayyahoo.add(jp_yahoo);
//
//        Tray traysearch = factory.createTray("检索引擎");
//        traysearch.add(excite);
//        traysearch.add(google);
//
//        Page page = factory.createPage("LinkPage", "张宇航");
//        page.add(traynews);
//        page.add(traysearch);
//        page.output();


//        Factory factory = Factory.getFactory(args[1]);
        Factory factory = Factory.getFactory(ListFactory.class);
        Class<?> aClass = Class.forName("com.wuyou.designPatterns.factory.abstractfactory.factory.Factory", false, ClassLoader.getSystemClassLoader());
        Link people = factory.createLink("人民日报", "http://www.people.com.cn");
        Link gmw = factory.createLink("光明日报", "http://www.gmw.cn");

        Link us_yahoo = factory.createLink("Yahoo!", "http://yahoo.com");
        Link jp_yahoo = factory.createLink("Yahoo!Japan", "http://yahoo.co.jp");
        Link excite = factory.createLink("Excite", "http://www.excite.com");
        Link google = factory.createLink("Google", "http://www.google.com");

        Tray traynews = factory.createTray("日报");
        traynews.add(people);
        traynews.add(gmw);

        Tray trayyahoo = factory.createTray("Yahoo!");
        trayyahoo.add(us_yahoo);
        trayyahoo.add(jp_yahoo);

        Tray traysearch = factory.createTray("检索引擎");
        traysearch.add(excite);
        traysearch.add(google);

        Page page = factory.createPage("TablePage", "张宇航");
        page.add(traynews);
        page.add(traysearch);
        page.output();

    }
}
